package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.PcadvertisingDao;
import com.example.wujinapi.entity.Pcadvertising;
import com.example.wujinapi.service.PcadvertisingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 * @author Daniel
 * @since 2022-10-13
 */
@Slf4j
@Service("pcadvertisingService")
public class PcadvertisingServiceImpl extends ServiceImpl<PcadvertisingDao, Pcadvertising> implements PcadvertisingService {

    @Autowired
    private PcadvertisingDao pcadvertisingDao;

    @Override
    public int UpdatePcad(Pcadvertising pcadvertising) {
        Pcadvertising temp=pcadvertisingDao.selectOne(new QueryWrapper<Pcadvertising>().eq("adsort",pcadvertising.getAdsort()));
        if(temp!=null){
            //更新
            pcadvertising.setId(temp.getId());
            pcadvertisingDao.updateById(pcadvertising);
        }else{
            //插入
            pcadvertisingDao.insert(pcadvertising);
        }
        return 0; //0代表成功 1代表不成功
    }


    @Override
    public List<Map<String,Object>> ReadPcad() {
        List<Map<String, Object>> pcAd=pcadvertisingDao.selectMaps(new QueryWrapper<Pcadvertising>().isNotNull("id").eq("status","已审核").eq("isshow",1));
        return pcAd;
    }

    @Override
    public Pcadvertising ReadPcadBySortNum(int num) {
        Pcadvertising data=pcadvertisingDao.selectOne(new QueryWrapper<Pcadvertising>().eq("adsort",num).eq("status","已审核").eq("isshow",1));
        return data;
    }
}
